# -*- coding:utf-8 -*-
from flask import request, jsonify, abort
from flask_cors import CORS
from com.zzh.dao_v2.viewIndusItem import ViewIndusItem

from . import app

CORS(app, supports_credentials=True)


@app.route('/queryIndusItemByCondition', methods=['POST'])
def queryIndusItemByCondition():
    if not request.json:
        abort(400)
    try:
        page = request.json['page']
        pageIndex = page["pageIndex"]
        pageSize = page["pageSize"]
    except:
        return jsonify({"message": {"code": 0, "status": "请传入 pageIndex和pageSize"}})

    try:
        conditions = request.json['condition']
    except:
        return jsonify({"message": {"code": 0, "status": "未传入指定condition"}})
    try:
        multiSort = request.json['multiSort']
    except:
        return jsonify({"message": "未传入排序规则multiSort"})

    info, total = ViewIndusItem().queryByCondition(pageIndex=pageIndex, pageSize=pageSize, conditions=conditions,
                                                  multiSort=multiSort)

    if info:
        return jsonify({"total": total, "info": info, "message": {"code": 1, "status": "success"}})
    else:
        return jsonify({"info": [], "message": {"code": 0, "status": "No data"}})


